package cz.muni.fi.pa165.creatures.model;

import java.io.Serializable;
import javax.persistence.Embeddable;
import javax.persistence.ManyToOne;

/**
 * Class which represents key in the many-to-many association table.
 * 
 * @author xmiklos1
 */
@Embeddable
public class CreatureTypeWeaponEffectivityId implements Serializable {

    /**
     * Weapon of the relation
     */
    private Weapon weapon;
    
    /**
     * CreatureType of the relation
     */
    private CreatureType creaturetype;

    /**
     * 
     * @return weapon 
     */
    @ManyToOne
    public Weapon getWeapon() {
        return weapon;
    }

    /**
     * 
     * @param weapon 
     */
    public void setWeapon(Weapon weapon) {
        this.weapon = weapon;
    }

    /**
     * 
     * @return creature type
     */
    @ManyToOne
    public CreatureType getCreaturetype() {
        return creaturetype;
    }

    /**
     * 
     * @param creatureType 
     */
    public void setCreaturetype(CreatureType creatureType) {
        this.creaturetype = creatureType;
    }

    @Override
    public String toString() {
        return "CreatureTypeWeaponEffectivityId{" + "weapon=" + weapon 
                + ", creaturetype=" + creaturetype + '}';
    }
    
    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        CreatureTypeWeaponEffectivityId that = (CreatureTypeWeaponEffectivityId) o;

        if (weapon != null ? !weapon.equals(that.weapon) : that.weapon != null) {
            return false;
        }
        if (creaturetype != null ? !creaturetype.equals(that.creaturetype) 
                : that.creaturetype != null) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int result;
        result = (weapon != null ? weapon.hashCode() : 0);
        result = 31 * result + (creaturetype != null ? creaturetype.hashCode() : 0);
        return result;
    }
}
